package com.xr.pfm.demo;

import com.xr.common.CommUtil;
import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * makeEmpPfmViewModel
 */
public class makeEmpPfmViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  Dataset dsEmp=getDataset("datasetEmp");
	  Dataset dsPfm=getDataset("datasetPfm");
	  DBStatement dbs =new DBStatement();
      CommUtil.dbsUpdateData(dbs, dsEmp, "PFM_RESULT", "PFM_RESULT_ID");
      
      RecordIterator ri1 = dsPfm.recordIterator();
      ri1.setVisibility(Dataset.FILTER_NEW);
      while (ri1.hasNext()) {
        Record record = ri1.nextRecord();
        record.setValue("PFM_RESULT_ID", dsEmp.getString("PFM_RESULT_ID"));
      
      }
      
     /* dsPfm.moveFirst();
      while(!dsPfm.isLast()){
    	  dsPfm.setValue("PFM_RESULT_ID", dsEmp.getString("PFM_RESULT_ID"));
    	  dsPfm.moveNext();
      }*/
      CommUtil.dbsUpdateData(dbs, dsPfm, "PFM_CHECKITEM_DEMO", "CHECKITEM_ID");
      dbs.close();
      
      
      RecordIterator ri = dsPfm.recordIterator();
      ri.setVisibility(Dataset.FILTER_DELETED);
      while (ri.hasNext()) {
        Record record = ri.nextRecord();
        CommUtil.executeUpdate(dbs,"delete from PFM_CHECKITEM_DEMO where CHECKITEM_ID="+record.getString("CHECKITEM_ID"));
        CommUtil.executeUpdate(dbs,"delete from PFM_CHECKITEM_DEMO where SUPER_CHECKITEM_ID="+record.getString("CHECKITEM_ID"));
      }
      dbs.close();
      outParameters.setValue("OUTP_PFM_RESULT_ID", dsEmp.getString("PFM_RESULT_ID"));
    //super.doUpdateData(parameters, outParameters);
  }
  
  public void checkWeight(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
		DoradoContext context = DoradoContext.getContext();
		DBStatement dbs = new DBStatement();
		Dataset ds=getDataset("datasetEmp");
		
		CommUtil.executeUpdate(dbs, "begin pck_pfm.checkWeight("+ds.getString("PFM_RESULT_ID")+"); end;");
		

  }

}
